<template>
	<view class="container">
		<view class="list">
			<view class="item bg-fff" v-for="(item,index) in list" :key="index">
				<view class="item-title flex-space-between">
					<view>发票抬头</view>
					<view>{{item.title || ""}}</view>
				</view>
				<view class="item-tips">联系人：{{item.name || ""}}</view>
				<view class="item-tips">联系电话：{{item.phone || ""}}</view>
				<view class="item-tips">税号：{{item.code || ""}}</view>
				
				<view class="item-operate flex-align-center">
					<text @click="handleDelete(item)">删除</text>
					<text @click="jump('/pages/mine/invoice/info?id='+item.id)">修改</text>
				</view>
			</view>
		</view>
		
		<b-u-button-theme width="100%" height="90rpx" @click="jump('/pages/mine/invoice/info')">添加抬头</b-u-button-theme>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.getHttp();
		},
		methods: {
			handleDelete(item) {
				uni.showModal({
					title: '提示',
					content: '删除这个发票抬头？',
					success: (res) => {
						if (res.confirm) {
							uni.$u.api.postDeleteInvoice({id: item.id}).then(res => {
								this.getInvoice();
							})
							// console.log('用户点击确定');
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			jump(url) {
				uni.navigateTo({
					url: url
				})
			},
			getInvoice() {
				uni.$u.api.getInvoice(this.pageForm).then(res => {
					this.list = res;
				})
			},
			getHttp() {
				this.getInvoice();
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		padding: 20rpx 30rpx;
		
		.list {
			margin-bottom: 60rpx;
			
			.item {
				margin-bottom: 24rpx;
				border-radius: 16rpx;
				padding: 20rpx 40rpx;
				
				.item-title {
					padding-bottom: 20rpx;
					border-bottom: 1px dashed #D8D8D8;
					margin-bottom: 20rpx;
				}
				
				.item-tips {
					margin-top: 4rpx;
					font-size: 24rpx;
					color: #666666;
				}
				
				.item-operate {
					margin-top: 20rpx;
					justify-content: flex-end;
					
					text {
						font-size: 24rpx;
						color: #666666;
						margin-left: 50rpx;
					}
				}
			}
		}
	}
</style>
